from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-21 14:02:49.963871
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 21, Apr, 2022
Time: 14:02:55
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.0279
Nobs: 633.000 HQIC: -49.4150
Log likelihood: 7723.92 FPE: 2.70794e-22
AIC: -49.6607 Det(Omega_mle): 2.35165e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.329214 0.062568 5.262 0.000
L1.Burgenland 0.105727 0.039623 2.668 0.008
L1.Kärnten -0.110369 0.020757 -5.317 0.000
L1.Niederösterreich 0.196426 0.082816 2.372 0.018
L1.Oberösterreich 0.120583 0.081652 1.477 0.140
L1.Salzburg 0.259069 0.042035 6.163 0.000
L1.Steiermark 0.042740 0.055289 0.773 0.440
L1.Tirol 0.104195 0.044753 2.328 0.020
L1.Vorarlberg -0.064812 0.039511 -1.640 0.101
L1.Wien 0.023416 0.072372 0.324 0.746
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051296 0.133919 0.383 0.702
L1.Burgenland -0.035977 0.084808 -0.424 0.671
L1.Kärnten 0.041469 0.044429 0.933 0.351
L1.Niederösterreich -0.198469 0.177257 -1.120 0.263
L1.Oberösterreich 0.451870 0.174767 2.586 0.010
L1.Salzburg 0.284986 0.089970 3.168 0.002
L1.Steiermark 0.109114 0.118339 0.922 0.357
L1.Tirol 0.309132 0.095789 3.227 0.001
L1.Vorarlberg 0.025479 0.084569 0.301 0.763
L1.Wien -0.030219 0.154904 -0.195 0.845
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189409 0.031998 5.919 0.000
L1.Burgenland 0.089417 0.020264 4.413 0.000
L1.Kärnten -0.007522 0.010616 -0.709 0.479
L1.Niederösterreich 0.245319 0.042354 5.792 0.000
L1.Oberösterreich 0.160234 0.041759 3.837 0.000
L1.Salzburg 0.040565 0.021497 1.887 0.059
L1.Steiermark 0.026606 0.028276 0.941 0.347
L1.Tirol 0.084201 0.022888 3.679 0.000
L1.Vorarlberg 0.054710 0.020207 2.708 0.007
L1.Wien 0.118653 0.037013 3.206 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111176 0.032096 3.464 0.001
L1.Burgenland 0.043596 0.020326 2.145 0.032
L1.Kärnten -0.013534 0.010648 -1.271 0.204
L1.Niederösterreich 0.175616 0.042483 4.134 0.000
L1.Oberösterreich 0.332299 0.041886 7.933 0.000
L1.Salzburg 0.101860 0.021563 4.724 0.000
L1.Steiermark 0.111817 0.028362 3.942 0.000
L1.Tirol 0.093093 0.022958 4.055 0.000
L1.Vorarlberg 0.060195 0.020269 2.970 0.003
L1.Wien -0.016769 0.037126 -0.452 0.652
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112274 0.059975 1.872 0.061
L1.Burgenland -0.045326 0.037981 -1.193 0.233
L1.Kärnten -0.045645 0.019897 -2.294 0.022
L1.Niederösterreich 0.139244 0.079384 1.754 0.079
L1.Oberösterreich 0.162883 0.078268 2.081 0.037
L1.Salzburg 0.284015 0.040292 7.049 0.000
L1.Steiermark 0.057558 0.052997 1.086 0.277
L1.Tirol 0.160977 0.042898 3.753 0.000
L1.Vorarlberg 0.098203 0.037874 2.593 0.010
L1.Wien 0.078122 0.069373 1.126 0.260
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058438 0.047132 1.240 0.215
L1.Burgenland 0.027851 0.029848 0.933 0.351
L1.Kärnten 0.052601 0.015637 3.364 0.001
L1.Niederösterreich 0.199858 0.062385 3.204 0.001
L1.Oberösterreich 0.328946 0.061508 5.348 0.000
L1.Salzburg 0.038273 0.031665 1.209 0.227
L1.Steiermark 0.008983 0.041649 0.216 0.829
L1.Tirol 0.124475 0.033712 3.692 0.000
L1.Vorarlberg 0.065633 0.029764 2.205 0.027
L1.Wien 0.095922 0.054518 1.759 0.078
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170025 0.056510 3.009 0.003
L1.Burgenland 0.005166 0.035787 0.144 0.885
L1.Kärnten -0.065244 0.018748 -3.480 0.001
L1.Niederösterreich -0.100785 0.074798 -1.347 0.178
L1.Oberösterreich 0.206571 0.073747 2.801 0.005
L1.Salzburg 0.055455 0.037965 1.461 0.144
L1.Steiermark 0.241769 0.049936 4.842 0.000
L1.Tirol 0.500822 0.040420 12.390 0.000
L1.Vorarlberg 0.064091 0.035686 1.796 0.072
L1.Wien -0.075370 0.065365 -1.153 0.249
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148373 0.062595 2.370 0.018
L1.Burgenland -0.000376 0.039640 -0.009 0.992
L1.Kärnten 0.062132 0.020766 2.992 0.003
L1.Niederösterreich 0.172474 0.082852 2.082 0.037
L1.Oberösterreich -0.055383 0.081688 -0.678 0.498
L1.Salzburg 0.208357 0.042053 4.955 0.000
L1.Steiermark 0.139353 0.055313 2.519 0.012
L1.Tirol 0.060113 0.044773 1.343 0.179
L1.Vorarlberg 0.147566 0.039528 3.733 0.000
L1.Wien 0.119757 0.072404 1.654 0.098
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.378069 0.036975 10.225 0.000
L1.Burgenland -0.002233 0.023416 -0.095 0.924
L1.Kärnten -0.021163 0.012267 -1.725 0.084
L1.Niederösterreich 0.207730 0.048941 4.244 0.000
L1.Oberösterreich 0.229290 0.048254 4.752 0.000
L1.Salzburg 0.038796 0.024841 1.562 0.118
L1.Steiermark -0.012365 0.032674 -0.378 0.705
L1.Tirol 0.091110 0.026447 3.445 0.001
L1.Vorarlberg 0.052717 0.023350 2.258 0.024
L1.Wien 0.040377 0.042769 0.944 0.345
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036228 0.111763 0.172806 0.140314 0.101670 0.083223 0.036774 0.209134
Kärnten 0.036228 1.000000 -0.023983 0.132835 0.051212 0.087916 0.442908 -0.064799 0.090839
Niederösterreich 0.111763 -0.023983 1.000000 0.318730 0.126331 0.279328 0.071357 0.156826 0.293595
Oberösterreich 0.172806 0.132835 0.318730 1.000000 0.218011 0.304194 0.168781 0.142015 0.243842
Salzburg 0.140314 0.051212 0.126331 0.218011 1.000000 0.128042 0.095406 0.107932 0.126684
Steiermark 0.101670 0.087916 0.279328 0.304194 0.128042 1.000000 0.137940 0.113484 0.043135
Tirol 0.083223 0.442908 0.071357 0.168781 0.095406 0.137940 1.000000 0.066006 0.150157
Vorarlberg 0.036774 -0.064799 0.156826 0.142015 0.107932 0.113484 0.066006 1.000000 -0.000375
Wien 0.209134 0.090839 0.293595 0.243842 0.126684 0.043135 0.150157 -0.000375 1.000000